package jmetal.metaheuristics.grdea.utils;

import java.lang.reflect.Constructor;

import jmetal.core.Problem;
import jmetal.core.Solution;
import jmetal.core.SolutionSet;

public class DynamicUtils {

	public static Problem reDefinedProblem(SolutionSet population, Problem problem, int cycle) throws Exception {
		Class<?> clazz = problem.getClass();
		Constructor<?> constr = clazz.getConstructor(Integer.class, Integer.class);
		problem = (Problem) constr.newInstance(problem.getNumberOfVariables(), cycle);
		for(int i = 0;i<population.size();i++){
			//重新评估
			Solution solution = population.get(i);
			Solution newSolution = new Solution(solution,problem.getNumberOfObjectives());
			problem.evaluate(newSolution);
			population.set(i, newSolution);
		}
		return problem;
	}
	
}
